package com.sgb.kjwl.viewmodel.machine;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.google.gson.Gson;
import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.AskLeaseFarmEntity;
import com.sgb.kjwl.model.entity.lease.AskLeaseItemEntity;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.model.entity.transport.MapLongAndLatEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.model.entity.user.UnitEntity;
import com.sgb.kjwl.view.widget.TwoRangePopWindow;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MLog;
import com.swgk.core.util.PickSelectEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AskLeaseCommonModel extends ViewModel {
    public MutableLiveData<List<PickSelectEntity>> showRateLiveData = new MutableLiveData<>();
//    public MutableLiveData<List<PickSelectEntity>> invoicesLiveData = new MutableLiveData<>();//发票类型数据
    public MutableLiveData<List<PickSelectEntity>> driverAgeLiveData = new MutableLiveData<>();
    public MutableLiveData<List<PickSelectEntity<List<PickSelectEntity>>>> leaseTimeUnitLiveData = new MutableLiveData<>();//租赁时长单位
    public List<PickSelectEntity> getInvoiceData() {
        List<PickSelectEntity> list = new ArrayList<>();
        list.add(new PickSelectEntity("2", "不需要发票"));
        list.add(new PickSelectEntity("0", "普通发票"));
        list.add(new PickSelectEntity("1", "专用发票"));
        return list;
    }

    public List<PickSelectEntity> getTimeTypeData() {
        List<PickSelectEntity> list = new ArrayList<>();
        list.add(new PickSelectEntity("0", "日"));
        list.add(new PickSelectEntity("1", "月"));
        list.add(new PickSelectEntity("2", "年"));
        return list;
    }

    //获取驾驶员年龄
    public void getDriverAgeDatas(){
        List<PickSelectEntity> list = new ArrayList<>();
        list.add(new PickSelectEntity("0", "不限"));
        list.add(new PickSelectEntity("1", "1年以上"));
        list.add(new PickSelectEntity("2", "3年以上"));
        list.add(new PickSelectEntity("3", "5年以上"));
        list.add(new PickSelectEntity("4", "7年以上"));
        list.add(new PickSelectEntity("5", "10年以上"));
        driverAgeLiveData.postValue(list);
    }
    /**
     * 租赁时长单位
     * type区分 0机械1设备2车辆3房产4土地5工厂6农机
     */
    public void getLeaseTimeUnit(String type){
        Map map= new HashMap();
        map.put("pageSize",20);
        map.put("pageNum",1);
        map.put("type",type);

        APIManager.getInstance().getLeaseAPI().getLeaseTimeUnit(map).enqueue(new Callback<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> call, Response<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> response) {
                if (response.body() == null || response.body().getState() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    leaseTimeUnitLiveData.postValue(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> call, Throwable t) {
            }
        });
    }

    //获取税率列表
    public void getLeaseRate() {
        APIManager.getInstance().getLeaseAPI().getLeaseRate().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null || response.body().getState() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    showRateLiveData.postValue(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
            }
        });
    }

    public List<TwoRangePopWindow.SourceEntity> getAgeData(int start, int end) {
        List<TwoRangePopWindow.SourceEntity> mOptionsItems = new ArrayList<>();
        for (int i = start; i <= end; i++) {
            mOptionsItems.add(new TwoRangePopWindow.SourceEntity(i + "", i));
        }
        return mOptionsItems;
    }
}
